from devicetest.aw.OpenHarmony import CommonOH, DeviceInfoHelper
from devicetest.core.test_case import TestCase, Step

from aw.common import common_setup, common_teardown
from aw.pom import Setting, DeskTop


class PreTest_RK3568_Basic_Setting_4100(TestCase, Setting):
    # 预置条件：
    # 烧写目标版本后，正常进入桌面
    # 测试步骤：
    # 1.进入桌面，点击设置-系统-语言设置-语言与地区-语言
    # 2.点击添加语言
    # 预期结果：
    # 1.可正常进入语言设置
    # 2.选择添加并更改为该语言后桌面所有信息都显示为该语言

    def __init__(self, controllers):
        self.TAG = self.__class__.__name__
        TestCase.__init__(self, self.TAG, controllers)

    def setup(self):
        common_setup(self.Phone1)
        DeviceInfoHelper.setSystemLanguage(self.Phone1, 'zh-Hans')

    def process(self):
        Step('步骤1：进入桌面，点击设置-系统-语言设置-语言与地区-语言')
        CommonOH.startAbility(self.Phone1, self.ability_name, self.bundle_name)
        CommonOH.wait(self.Phone1, 1)
        CommonOH.swipe(self.Phone1, **DeskTop.swipe_up)
        CommonOH.wait(self.Phone1, 3)
        CommonOH.touchByText(self.Phone1, '系统')
        CommonOH.touchByText(self.Phone1, '语言设置')
        CommonOH.touchByText(self.Phone1, '语言与地区')
        Step('预期结果1：可正常进入语言设置')
        CommonOH.checkIfTextExist(self.Phone1, '添加语言')

        Step('步骤2：点击添加语言')
        # 第一个是恢复出厂设置页面的重置，第二个相当于确认重置，两个不在同一个页面
        CommonOH.touchByText(self.Phone1, '添加语言')
        CommonOH.touchByText(self.Phone1, 'English')
        CommonOH.touchByText(self.Phone1, '更改')
        CommonOH.wait(self.Phone1, 0.5)
        Step('预期结果2: 选择添加并更改为该语言后桌面所有信息都显示为该语言')
        CommonOH.checkIfTextExist(self.Phone1, 'Add Language')
        CommonOH.goBack(self.Phone1)
        CommonOH.checkIfTextExist(self.Phone1, 'Set Language')
        CommonOH.goBack(self.Phone1)
        CommonOH.checkIfTextExist(self.Phone1, 'System & Updates')
        CommonOH.goBack(self.Phone1)
        CommonOH.checkIfTextExist(self.Phone1, 'Settings')
        CommonOH.goBack(self.Phone1)
        CommonOH.checkIfTextExist(self.Phone1, 'Camera')

    def teardown(self):
        common_teardown(self.Phone1, self.bundle_name)
        DeviceInfoHelper.setSystemLanguage(self.Phone1, 'zh-Hans')
